package com.linxz.framework.module;

import com.linxz.framework.base.ActivityLifeCycleEvent;
import com.linxz.framework.base.module.BaseModel;
import com.linxz.framework.bean.LoginResp;
import com.linxz.framework.bean.UserBean;
import com.linxz.framework.protocol.MineApiStore;
import com.linxz.framework.protocol.callback.HttpCallBack;
import com.linxz.framework.protocol.callback.ModelCallBack;

import io.reactivex.subjects.PublishSubject;

/**
 * @author Linxz
 * 创建日期：2020年12月14日 15:38
 * version：
 * 描述：
 */
public class UserModule extends BaseModel {
    private MineApiStore mineApiStore;
    public UserModule(PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        super(lifecycleSubject);
        mineApiStore=getOutApiStore(MineApiStore.class);
    }

    public void login(String mobile, String password, final ModelCallBack<UserBean> modelCallBack){
        toSubscribe(mineApiStore.register(mobile,password),new HttpCallBack<LoginResp>(){
            @Override
            public void onErrors(String code, String msg) {
                modelCallBack.onErrors(code,msg);
            }

            @Override
            public void onResponse(LoginResp loginResp) {
                if (loginResp.isOk()){
                    modelCallBack.onSuccess(loginResp.getData());
                }else{
                    modelCallBack.onErrors(loginResp.getStatus(),loginResp.getMsg());
                }

            }
        });
    }
}
